﻿using AutoMapper;
using MediatR;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.CheckProductWorkCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.CheckProductWorkCommandHandlers
{
    public class AddCheckProductWorkCommandHandler : IRequestHandler<AddCheckProductWorkCommand, ApiResult<int>>
    {
        IBaseRepository<CheckProductWork> CheckProductWork;
        IMapper mapper;
        public AddCheckProductWorkCommandHandler(IBaseRepository<CheckProductWork> CheckProductWork, IMapper mapper)
        {
            this.CheckProductWork = CheckProductWork;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(AddCheckProductWorkCommand request, CancellationToken cancellationToken)
        {

            var model = mapper.Map<CheckProductWork>(request);
           int number= CheckProductWork.Add(model).Result;
            return new ApiResult<int> 
            {
                   Code=ApiEnum.success,
                   Message="添加成功",
                   Data= number
            };
        }
    }
}
